<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>benedettelli-nxt2wifi.h</h1>  </div>
</div>
<div class="contents">
<a href="benedettelli-nxt2wifi_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*!@addtogroup other</span>
<a name="l00002"></a>00002 <span class="comment"> * @{</span>
<a name="l00003"></a>00003 <span class="comment"> * @defgroup NXT2WIFI NXT2WIFI Wifi Sensor</span>
<a name="l00004"></a>00004 <span class="comment"> * Dani&#39;s WiFi Sensor</span>
<a name="l00005"></a>00005 <span class="comment"> * @{</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">/*</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: benedettelli-nxt2wifi.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#ifndef __N2W_H__</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define __N2W_H__</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="comment">/** \file benedettelli-nxt2wifi.h</span>
<a name="l00015"></a>00015 <span class="comment"> * \brief Dani&#39;s WiFi Sensor</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * benedettelli-nxt2wifi.h provides an API for Dani&#39;s WiFi Sensor.\n</span>
<a name="l00018"></a>00018 <span class="comment"> *</span>
<a name="l00019"></a>00019 <span class="comment"> * Changelog:</span>
<a name="l00020"></a>00020 <span class="comment"> * - 0.1: Initial release</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * Credits:</span>
<a name="l00023"></a>00023 <span class="comment"> * - Big thanks to Dani for providing me with the hardware necessary to write and test this.</span>
<a name="l00024"></a>00024 <span class="comment"> *</span>
<a name="l00025"></a>00025 <span class="comment"> * License: You may use this code as you wish, provided you give credit where its due.</span>
<a name="l00026"></a>00026 <span class="comment"> *</span>
<a name="l00027"></a>00027 <span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<a name="l00028"></a>00028 <span class="comment"></span>
<a name="l00029"></a>00029 <span class="comment"> * \author Xander Soldaat (xander_at_botbench.com)</span>
<a name="l00030"></a>00030 <span class="comment"> * \date 12 June 2012</span>
<a name="l00031"></a>00031 <span class="comment"> * \version 0.1</span>
<a name="l00032"></a>00032 <span class="comment"> * \example benedettelli-nxt2wifi-test1.c</span>
<a name="l00033"></a>00033 <span class="comment"> * \example benedettelli-nxt2wifi-test2.c</span>
<a name="l00034"></a>00034 <span class="comment"> * \example benedettelli-nxt2wifi-test3.c</span>
<a name="l00035"></a>00035 <span class="comment"> * \example benedettelli-nxt2wifi-test4.c</span>
<a name="l00036"></a>00036 <span class="comment"> */</span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 <span class="preprocessor">#pragma systemFile</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span>
<a name="l00040"></a>00040 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#endif</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span>
<a name="l00044"></a>00044 <span class="preprocessor">#ifndef __RS485_H__</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common-rs485_8h.html" title="Commonly used RS485-related functions used by drivers.">common-rs485.h</a>&quot;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#endif</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>
<a name="l00048"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga836415b43af37073c0c5e836964c143d">00048</a> <span class="preprocessor">#define WS_WEBLABEL                 1   </span><span class="comment">/*!&lt; Web page widget: label */</span>
<a name="l00049"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga79b10de1bbc136ce1c87b199df74b328">00049</a> <span class="preprocessor">#define WS_WEBBUTTON                2   </span><span class="comment">/*!&lt; Web page widget: button */</span>
<a name="l00050"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga8fa9ff8becf8b102935c2347348a0541">00050</a> <span class="preprocessor">#define WS_WEBCHECKBOX              3   </span><span class="comment">/*!&lt; Web page widget: checkbox */</span>
<a name="l00051"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gadeeafa26002e50f63f6528cca7c3d214">00051</a> <span class="preprocessor">#define WS_WEBSLIDER                4   </span><span class="comment">/*!&lt; Web page widget: slider */</span>
<a name="l00052"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga5346e56803b6b76f95b726f15ce98ffc">00052</a> <span class="preprocessor">#define WS_WEBBARGRAPH              5   </span><span class="comment">/*!&lt; Web page widget: bargraph */</span>
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaa60f94528dbd526efe51621a5dcfbb38">00054</a> <span class="preprocessor">#define WF_SEC_OPEN                                           0   </span><span class="comment">/*!&lt; Open Security (none) */</span>
<a name="l00055"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga4458353a505e877aad1243213fb71dbf">00055</a> <span class="preprocessor">#define WF_SEC_WEP_40                                 1   </span><span class="comment">/*!&lt; 40 bit WEP  */</span>
<a name="l00056"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaca898382d4e569493104f07b8c2e7ff1">00056</a> <span class="preprocessor">#define WF_SEC_WEP_104                                2   </span><span class="comment">/*!&lt; 104 bit WEP */</span>
<a name="l00057"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gae77b53f74bc682576506fa705eaf94b9">00057</a> <span class="preprocessor">#define WF_SEC_WPA_KEY                                3   </span><span class="comment">/*!&lt; WPA using key */</span>
<a name="l00058"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaa9999e5e1077bb65f4189c1743697924">00058</a> <span class="preprocessor">#define WF_SEC_WPA_PASSPHRASE       4   </span><span class="comment">/*!&lt; WPA using passphrase */</span>
<a name="l00059"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga6364769e8bdd334175c212ac47c512a4">00059</a> <span class="preprocessor">#define WF_SEC_WPA2_KEY                               5   </span><span class="comment">/*!&lt; WPA2 using key */</span>
<a name="l00060"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga40084a38a35caccb8e963fdbe07223c4">00060</a> <span class="preprocessor">#define WF_SEC_WPA2_PASSPHRASE      6   </span><span class="comment">/*!&lt; WPA2 using passphrase */</span>
<a name="l00061"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gad65a4494e2b294d3f81958520c489aec">00061</a> <span class="preprocessor">#define WF_SEC_WPA_AUTO_KEY                 7   </span><span class="comment">/*!&lt; Automatically determine WPA type and use key */</span>
<a name="l00062"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga92402209ad3288da331561197087fc92">00062</a> <span class="preprocessor">#define WF_SEC_WPA_AUTO_PASSPHRASE  8   </span><span class="comment">/*!&lt; Automatically determine WPA type and use passphrase */</span>
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga88627dd4a9dfeb11d2f4968279c79f3c">00064</a> <span class="preprocessor">#define AD_HOC 1</span>
<a name="l00065"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga13431962e4ad8005509bc9bf2e5fc84c">00065</a> <span class="preprocessor"></span><span class="preprocessor">#define INFRASTRUCTURE 0</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span>
<a name="l00067"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">00067</a> <span class="preprocessor">#define N2WchillOut()  wait1Msec(50)                   </span><span class="comment">/*!&lt; Wait 50ms between messages, this allows transmission to be done */</span>
<a name="l00068"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gabd2bf227781700379357eb2eb4789716">00068</a> <span class="preprocessor">#define N2WsetIPAddress(X)    _N2WsetPar(&quot;IPAD&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the IP address */</span>
<a name="l00069"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga83de8a557b9f8fd353d23ddc51d504f9">00069</a> <span class="preprocessor">#define N2WsetMask(X)         _N2WsetPar(&quot;MASK&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the netmask */</span>
<a name="l00070"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gafb777c708309b5c4cd60d89e23715c00">00070</a> <span class="preprocessor">#define N2WsetGateway(X)      _N2WsetPar(&quot;GWAY&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the gateway IP address */</span>
<a name="l00071"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaaebef4a719423f5116644ac1aeecc761">00071</a> <span class="preprocessor">#define N2WsetDNS1(X)         _N2WsetPar(&quot;DNS1&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the first DNS server IP address */</span>
<a name="l00072"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga378d37e736e65129349ee607b310789a">00072</a> <span class="preprocessor">#define N2WsetDNS2(X)         _N2WsetPar(&quot;DNS2&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the second DNS server IP address */</span>
<a name="l00073"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga54b23c839a31c2223453e622f4867440">00073</a> <span class="preprocessor">#define N2WsetSSID(X)         _N2WsetPar(&quot;SSID&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the SSID to connect to */</span>
<a name="l00074"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga6fbee78a45297f6c914bde21f28092b8">00074</a> <span class="preprocessor">#define N2WsetNetbiosName(X)  _N2WsetPar(&quot;NAME&quot;, X) </span><span class="comment">/*!&lt; Macro for setting the Netbios Name */</span>
<a name="l00075"></a>00075 
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 
<a name="l00078"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">00078</a> <span class="keywordtype">string</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>;   <span class="comment">/*!&lt; string for tmp formatting, scratch data */</span>
<a name="l00079"></a>00079 
<a name="l00080"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga59c656c794486f425bc8ec1dd566566b">00080</a> intrinsic <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *sSrce, <span class="keyword">const</span> <span class="keywordtype">char</span> *pzFindString)    <span class="keyword">asm</span>(opcdStringOps, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga59c656c794486f425bc8ec1dd566566b">strOpFind</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#gaac0d56706c00d98c12714caea471305f">variableRefCharPtr</a>(sSrce), <a class="code" href="group___n_x_t2_w_i_f_i.html#ga139740aa3106a37aac0bc2ec12c50abe">functionReturn</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#gaac0d56706c00d98c12714caea471305f">variableRefCharPtr</a>(pzFindString));
<a name="l00081"></a>00081 
<a name="l00082"></a>00082 <span class="comment"></span>
<a name="l00083"></a>00083 <span class="comment">/**</span>
<a name="l00084"></a>00084 <span class="comment"> * Parse the buffer and return the number in the NXT2WIFI response</span>
<a name="l00085"></a>00085 <span class="comment"> * @param buf the buffer to pull the number from</span>
<a name="l00086"></a>00086 <span class="comment"> * @return the number or -1 if no number found.</span>
<a name="l00087"></a>00087 <span class="comment"> */</span>
<a name="l00088"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">00088</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a> &amp;buf)
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090   <span class="keywordtype">long</span> retval = 0;
<a name="l00091"></a>00091   <span class="keywordtype">int</span> pos = 0;
<a name="l00092"></a>00092   <span class="keywordflow">for</span> (pos = 0; pos &lt; <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a>); pos++)
<a name="l00093"></a>00093   {
<a name="l00094"></a>00094     memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00095"></a>00095     memcpy(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, buf, 19);
<a name="l00096"></a>00096     pos = <a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;=&quot;</span>);
<a name="l00097"></a>00097     memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00098"></a>00098     memcpy(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, &amp;buf[pos+1], <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a>) - (pos + 1));
<a name="l00099"></a>00099     retval = atoi(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00100"></a>00100     <span class="keywordflow">return</span> retval;
<a name="l00101"></a>00101   }
<a name="l00102"></a>00102   <span class="keywordflow">return</span> 0;
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 <span class="comment"></span>
<a name="l00106"></a>00106 <span class="comment">/**</span>
<a name="l00107"></a>00107 <span class="comment"> * Parse the buffer and return the string in the NXT2WIFI response</span>
<a name="l00108"></a>00108 <span class="comment"> * @param buf the buffer to pull the string from</span>
<a name="l00109"></a>00109 <span class="comment"> * @param response the string to hold the response from the sensor</span>
<a name="l00110"></a>00110 <span class="comment"> */</span>
<a name="l00111"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga02cfed21ceafe387f51c2614ba4acc6b">00111</a> <span class="keywordtype">void</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga02cfed21ceafe387f51c2614ba4acc6b">N2WgetStringResponse</a>(<span class="keyword">const</span> <a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a> &amp;buf, <span class="keywordtype">string</span> &amp;response)
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113   <span class="keywordtype">int</span> pos = 0;
<a name="l00114"></a>00114 
<a name="l00115"></a>00115   memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00116"></a>00116   memcpy(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, buf, 19);
<a name="l00117"></a>00117   pos = <a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;=&quot;</span>);
<a name="l00118"></a>00118   memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00119"></a>00119   memcpy(response, &amp;buf[pos+1], 19);
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123 <span class="comment"></span>
<a name="l00124"></a>00124 <span class="comment">/**</span>
<a name="l00125"></a>00125 <span class="comment"> * Enable debugging</span>
<a name="l00126"></a>00126 <span class="comment"> * @param en whether or not to enable debugging</span>
<a name="l00127"></a>00127 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00128"></a>00128 <span class="comment"> */</span>
<a name="l00129"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaf9a6909ba65dbacaadea4e1264188dc3">00129</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gaf9a6909ba65dbacaadea4e1264188dc3">N2WsetDebug</a>(<span class="keywordtype">bool</span> en)
<a name="l00130"></a>00130 {
<a name="l00131"></a>00131   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = (en) ? <span class="stringliteral">&quot;$DBG1\n&quot;</span> : <span class="stringliteral">&quot;$DBG0\n&quot;</span>;
<a name="l00132"></a>00132   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00133"></a>00133   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00134"></a>00134     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00135"></a>00135   wait1Msec(10);
<a name="l00136"></a>00136   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00137"></a>00137   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 <span class="comment"></span>
<a name="l00141"></a>00141 <span class="comment">/**</span>
<a name="l00142"></a>00142 <span class="comment"> * Connect to the currently configured WiFi network</span>
<a name="l00143"></a>00143 <span class="comment"> * @param custom use the default or custom profile</span>
<a name="l00144"></a>00144 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00145"></a>00145 <span class="comment"> */</span>
<a name="l00146"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaa0c803e53ea5cd1221aed19eea5463f4">00146</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gaa0c803e53ea5cd1221aed19eea5463f4">N2WConnect</a>(<span class="keywordtype">bool</span> custom)
<a name="l00147"></a>00147 {
<a name="l00148"></a>00148   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = (custom) ? <span class="stringliteral">&quot;$WFC1\n&quot;</span> : <span class="stringliteral">&quot;$WFC0\n&quot;</span>;
<a name="l00149"></a>00149   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00150"></a>00150   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00151"></a>00151     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00152"></a>00152   wait1Msec(10);
<a name="l00153"></a>00153   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00154"></a>00154   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 
<a name="l00157"></a>00157 <span class="comment"></span>
<a name="l00158"></a>00158 <span class="comment">/**</span>
<a name="l00159"></a>00159 <span class="comment"> * Disconnect from the current WiFi network</span>
<a name="l00160"></a>00160 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00161"></a>00161 <span class="comment"> */</span>
<a name="l00162"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga8ec5d0f6add0e5d953ad690f109a3253">00162</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8ec5d0f6add0e5d953ad690f109a3253">N2WDisconnect</a>() {
<a name="l00163"></a>00163   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;$WFX\n&quot;</span>;
<a name="l00164"></a>00164   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00165"></a>00165   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00166"></a>00166     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00167"></a>00167   wait1Msec(10);
<a name="l00168"></a>00168   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00169"></a>00169   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 
<a name="l00172"></a>00172 <span class="comment"></span>
<a name="l00173"></a>00173 <span class="comment">/**</span>
<a name="l00174"></a>00174 <span class="comment"> * Stop reconnecting when disconnected</span>
<a name="l00175"></a>00175 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00176"></a>00176 <span class="comment"> */</span>
<a name="l00177"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga08460ccd558f382eb3006f702aa3023b">00177</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga08460ccd558f382eb3006f702aa3023b">N2WStopConnecting</a>()
<a name="l00178"></a>00178 {
<a name="l00179"></a>00179   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFQ\n&quot;</span>))
<a name="l00180"></a>00180     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00181"></a>00181   <span class="comment">//N2WscratchString = &quot;$WFQ\n&quot;;</span>
<a name="l00182"></a>00182   <span class="comment">//memcpy(RS485txbuffer, N2WscratchString, strlen(N2WscratchString));</span>
<a name="l00183"></a>00183   <span class="comment">//if (!RS485write(RS485txbuffer, strlen(N2WscratchString)))</span>
<a name="l00184"></a>00184   <span class="comment">//  return false;</span>
<a name="l00185"></a>00185   wait1Msec(10);
<a name="l00186"></a>00186   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00187"></a>00187   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189 
<a name="l00190"></a>00190 <span class="comment"></span>
<a name="l00191"></a>00191 <span class="comment">/**</span>
<a name="l00192"></a>00192 <span class="comment"> * Delete the currently configured custom profile</span>
<a name="l00193"></a>00193 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00194"></a>00194 <span class="comment"> */</span>
<a name="l00195"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gad383fbc39e7e19cf1e8adead76cef112">00195</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gad383fbc39e7e19cf1e8adead76cef112">N2WDelete</a>()
<a name="l00196"></a>00196 {
<a name="l00197"></a>00197   <span class="keywordflow">if</span>(!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFKD\n&quot;</span>))
<a name="l00198"></a>00198     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00199"></a>00199   wait1Msec(10);
<a name="l00200"></a>00200   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00201"></a>00201   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="comment"></span>
<a name="l00205"></a>00205 <span class="comment">/**</span>
<a name="l00206"></a>00206 <span class="comment"> * Save the currently configured custom profile</span>
<a name="l00207"></a>00207 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00208"></a>00208 <span class="comment"> */</span>
<a name="l00209"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga553560298f91e301e85f226c21096f09">00209</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga553560298f91e301e85f226c21096f09">N2WSave</a>() {
<a name="l00210"></a>00210   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFKS\n&quot;</span>);
<a name="l00211"></a>00211   wait1Msec(10);
<a name="l00212"></a>00212   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00213"></a>00213   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215 
<a name="l00216"></a>00216 <span class="comment"></span>
<a name="l00217"></a>00217 <span class="comment">/**</span>
<a name="l00218"></a>00218 <span class="comment"> * Load the currently configured custom profile</span>
<a name="l00219"></a>00219 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00220"></a>00220 <span class="comment"> */</span>
<a name="l00221"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gac54a69b33b3a29473e8b4e80f993a401">00221</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gac54a69b33b3a29473e8b4e80f993a401">N2WLoad</a>() {
<a name="l00222"></a>00222   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFKL\n&quot;</span>))
<a name="l00223"></a>00223     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00224"></a>00224   wait1Msec(10);
<a name="l00225"></a>00225   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00226"></a>00226   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00227"></a>00227 }
<a name="l00228"></a>00228 
<a name="l00229"></a>00229 <span class="comment"></span>
<a name="l00230"></a>00230 <span class="comment">/**</span>
<a name="l00231"></a>00231 <span class="comment"> * Reset the NXT2WIFI sensor.</span>
<a name="l00232"></a>00232 <span class="comment"> */</span>
<a name="l00233"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gad0c6469f5376ee875c47a1ff36dd6f40">00233</a> <span class="keywordtype">void</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gad0c6469f5376ee875c47a1ff36dd6f40">N2WReset</a>()
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$RST\n&quot;</span>);
<a name="l00236"></a>00236 }
<a name="l00237"></a>00237 
<a name="l00238"></a>00238 <span class="comment"></span>
<a name="l00239"></a>00239 <span class="comment">/**</span>
<a name="l00240"></a>00240 <span class="comment"> * Confgure the security settings for the custom profile\n</span>
<a name="l00241"></a>00241 <span class="comment"> * Note: this is an internal function and shouldn&#39;t be used directly</span>
<a name="l00242"></a>00242 <span class="comment"> * @param mode the security mode to use</span>
<a name="l00243"></a>00243 <span class="comment"> * @param pKeypass the keypass to use</span>
<a name="l00244"></a>00244 <span class="comment"> * @param keylen the length of the key</span>
<a name="l00245"></a>00245 <span class="comment"> * @param keyind used for WEP, usually set to 0</span>
<a name="l00246"></a>00246 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00247"></a>00247 <span class="comment"> */</span>
<a name="l00248"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">00248</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<span class="keywordtype">int</span> mode, <span class="keyword">const</span> ubyte *pKeypass, <span class="keywordtype">int</span> keylen, <span class="keywordtype">int</span> keyind) {
<a name="l00249"></a>00249   <span class="keywordtype">int</span> index = 0;
<a name="l00250"></a>00250   writeDebugStreamLine(<span class="stringliteral">&quot;keylen: %d&quot;</span>, keylen);
<a name="l00251"></a>00251   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <span class="stringliteral">&quot;$WFS?&quot;</span>);
<a name="l00252"></a>00252   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;%d:&quot;</span>, mode);
<a name="l00253"></a>00253   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(RS485txbuffer, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00254"></a>00254   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(RS485txbuffer, index, pKeypass, keylen);
<a name="l00255"></a>00255   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;:%d\n&quot;</span>, keyind);
<a name="l00256"></a>00256   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(RS485txbuffer, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00257"></a>00257   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(RS485txbuffer, index);
<a name="l00258"></a>00258 }
<a name="l00259"></a>00259 
<a name="l00260"></a>00260 <span class="comment"></span>
<a name="l00261"></a>00261 <span class="comment">/**</span>
<a name="l00262"></a>00262 <span class="comment"> * Set the WPA2 key</span>
<a name="l00263"></a>00263 <span class="comment"> * @param key the WPA2 key to use</span>
<a name="l00264"></a>00264 <span class="comment"> * @param len the length of the WPA2 key</span>
<a name="l00265"></a>00265 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00266"></a>00266 <span class="comment"> */</span>
<a name="l00267"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga3ece92fa114544e0cae36bd70ffc5246">00267</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga3ece92fa114544e0cae36bd70ffc5246">N2WSecurityWPA2Key</a>(<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a> &amp;key, <span class="keywordtype">int</span> len) {
<a name="l00268"></a>00268         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga6364769e8bdd334175c212ac47c512a4">WF_SEC_WPA2_KEY</a>, &amp;key[0], len, 0);
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 
<a name="l00271"></a>00271 <span class="comment"></span>
<a name="l00272"></a>00272 <span class="comment">/**</span>
<a name="l00273"></a>00273 <span class="comment"> * Set the WPA2 passphrase</span>
<a name="l00274"></a>00274 <span class="comment"> * @param passphrase the WPA2 passphrase to use</span>
<a name="l00275"></a>00275 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00276"></a>00276 <span class="comment"> */</span>
<a name="l00277"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga37d426a308e6e59ba6ed37f086a26b7d">00277</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga37d426a308e6e59ba6ed37f086a26b7d">N2WSecurityWPA2Passphrase</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> passphrase) {
<a name="l00278"></a>00278   <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> tmpArray;
<a name="l00279"></a>00279         memcpy(tmpArray, passphrase, strlen(passphrase));
<a name="l00280"></a>00280         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga40084a38a35caccb8e963fdbe07223c4">WF_SEC_WPA2_PASSPHRASE</a>, &amp;tmpArray[0], strlen(passphrase), 0);
<a name="l00281"></a>00281 }
<a name="l00282"></a>00282 
<a name="l00283"></a>00283 <span class="comment"></span>
<a name="l00284"></a>00284 <span class="comment">/**</span>
<a name="l00285"></a>00285 <span class="comment"> * Set the WPA key</span>
<a name="l00286"></a>00286 <span class="comment"> * @param key the WPA key to use</span>
<a name="l00287"></a>00287 <span class="comment"> * @param len the length of the WPA key</span>
<a name="l00288"></a>00288 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00289"></a>00289 <span class="comment"> */</span>
<a name="l00290"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga2fcfa71c53a88200e346fd6dad218d03">00290</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga2fcfa71c53a88200e346fd6dad218d03">N2WSecurityWPAKey</a>(<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a> &amp;key, <span class="keywordtype">int</span> len) {
<a name="l00291"></a>00291         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#gae77b53f74bc682576506fa705eaf94b9">WF_SEC_WPA_KEY</a>, &amp;key[0], len, 0);
<a name="l00292"></a>00292 }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294 <span class="comment"></span>
<a name="l00295"></a>00295 <span class="comment">/**</span>
<a name="l00296"></a>00296 <span class="comment"> * Set the WPA passphrase</span>
<a name="l00297"></a>00297 <span class="comment"> * @param passphrase the WPA passphrase to use</span>
<a name="l00298"></a>00298 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00299"></a>00299 <span class="comment"> */</span>
<a name="l00300"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga59be7b814f305cd94528bf9de788e01f">00300</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga59be7b814f305cd94528bf9de788e01f">N2WSecurityWPAPassphrase</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;passphrase) {
<a name="l00301"></a>00301   <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> tmpArray;
<a name="l00302"></a>00302         memcpy(tmpArray, passphrase, strlen(passphrase));
<a name="l00303"></a>00303         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#gaa9999e5e1077bb65f4189c1743697924">WF_SEC_WPA_PASSPHRASE</a>, &amp;tmpArray[0], strlen(passphrase), 0);
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 
<a name="l00306"></a>00306 <span class="comment"></span>
<a name="l00307"></a>00307 <span class="comment">/**</span>
<a name="l00308"></a>00308 <span class="comment"> * Set the WEP passphrase.  Please don&#39;t use this, it&#39;s very insecure.</span>
<a name="l00309"></a>00309 <span class="comment"> * @param passphrase the WEP passphrase to use</span>
<a name="l00310"></a>00310 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00311"></a>00311 <span class="comment"> */</span>
<a name="l00312"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga67412608e97468088f257c8804402bd2">00312</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga67412608e97468088f257c8804402bd2">N2WSecurityWEP104</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;passphrase) {
<a name="l00313"></a>00313   <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> tmpArray;
<a name="l00314"></a>00314   writeDebugStreamLine(<span class="stringliteral">&quot;wep104: %d:&quot;</span>, strlen(passphrase));
<a name="l00315"></a>00315   writeDebugStreamLine(<span class="stringliteral">&quot;phrase: %s&quot;</span>, passphrase);
<a name="l00316"></a>00316         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#gaca898382d4e569493104f07b8c2e7ff1">WF_SEC_WEP_104</a>, passphrase, strlen(passphrase), 1);
<a name="l00317"></a>00317 }
<a name="l00318"></a>00318 
<a name="l00319"></a>00319 <span class="comment"></span>
<a name="l00320"></a>00320 <span class="comment">/**</span>
<a name="l00321"></a>00321 <span class="comment"> * Use no security at all.  Just as effective as WEP but less annoying.</span>
<a name="l00322"></a>00322 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00323"></a>00323 <span class="comment"> */</span>
<a name="l00324"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga876fa30db99edff7c4e1c195c7900b45">00324</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga876fa30db99edff7c4e1c195c7900b45">N2WSecurityOpen</a>() {
<a name="l00325"></a>00325   <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> tmpArray;
<a name="l00326"></a>00326         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga03bec35f600dc68742e303a48ac228f4">N2WSecurity</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#gaa60f94528dbd526efe51621a5dcfbb38">WF_SEC_OPEN</a>, &amp;tmpArray[0] , 0, 0);
<a name="l00327"></a>00327 }
<a name="l00328"></a>00328 
<a name="l00329"></a>00329 <span class="comment"></span>
<a name="l00330"></a>00330 <span class="comment">/**</span>
<a name="l00331"></a>00331 <span class="comment"> * Use ad-hoc network or infrastructure</span>
<a name="l00332"></a>00332 <span class="comment"> * @param adhoc if true, use adhoc, otherwise use infrastructure mode</span>
<a name="l00333"></a>00333 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00334"></a>00334 <span class="comment"> */</span>
<a name="l00335"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga1e5b1d9289e2509b55bff7910b684391">00335</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga1e5b1d9289e2509b55bff7910b684391">N2WsetAdHoc</a>(<span class="keywordtype">bool</span> adhoc) {
<a name="l00336"></a>00336   <span class="keywordflow">if</span> (adhoc)
<a name="l00337"></a>00337     <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFE?TYPE=1\n&quot;</span>);
<a name="l00338"></a>00338   <span class="keywordflow">else</span>
<a name="l00339"></a>00339     <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFE?TYPE=0\n&quot;</span>);
<a name="l00340"></a>00340   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00341"></a>00341   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00342"></a>00342 }
<a name="l00343"></a>00343 
<a name="l00344"></a>00344 <span class="comment"></span>
<a name="l00345"></a>00345 <span class="comment">/**</span>
<a name="l00346"></a>00346 <span class="comment"> * Set a specific parameter.\n</span>
<a name="l00347"></a>00347 <span class="comment"> * Note: this is an internal function and should not be used directly.</span>
<a name="l00348"></a>00348 <span class="comment"> * @param type the parameter type</span>
<a name="l00349"></a>00349 <span class="comment"> * @param param the value to pass to the parameter</span>
<a name="l00350"></a>00350 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00351"></a>00351 <span class="comment"> */</span>
<a name="l00352"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga1ff61d887ca3752378b26e63f6abace9">00352</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga1ff61d887ca3752378b26e63f6abace9">_N2WsetPar</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> type, <span class="keyword">const</span> <span class="keywordtype">string</span> param) {
<a name="l00353"></a>00353   <span class="keywordtype">int</span> index = 0;
<a name="l00354"></a>00354         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;$WFE?&quot;</span>;
<a name="l00355"></a>00355         index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00356"></a>00356         index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)RS485txbuffer, index, type);
<a name="l00357"></a>00357         index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)RS485txbuffer, index, <span class="stringliteral">&quot;=&quot;</span>);
<a name="l00358"></a>00358         index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)RS485txbuffer, index, param);
<a name="l00359"></a>00359         index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)RS485txbuffer, index, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00360"></a>00360   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(RS485txbuffer, index);
<a name="l00361"></a>00361 }
<a name="l00362"></a>00362 
<a name="l00363"></a>00363 <span class="comment"></span>
<a name="l00364"></a>00364 <span class="comment">/**</span>
<a name="l00365"></a>00365 <span class="comment"> * Configure to use DHCP.</span>
<a name="l00366"></a>00366 <span class="comment"> * @param yes if set to true, use DHCP</span>
<a name="l00367"></a>00367 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00368"></a>00368 <span class="comment"> */</span>
<a name="l00369"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga6c52b871d1aed83b3dee0c69369b4dd5">00369</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga6c52b871d1aed83b3dee0c69369b4dd5">N2WsetDHCP</a>(<span class="keywordtype">bool</span> yes) {
<a name="l00370"></a>00370   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = (yes) ? <span class="stringliteral">&quot;$WFE?DHCP=1\n&quot;</span> : <span class="stringliteral">&quot;$WFE?DHCP=0\n&quot;</span>;
<a name="l00371"></a>00371 
<a name="l00372"></a>00372   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00373"></a>00373   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00374"></a>00374     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00375"></a>00375   wait1Msec(10);
<a name="l00376"></a>00376   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00377"></a>00377   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379 
<a name="l00380"></a>00380 <span class="comment"></span>
<a name="l00381"></a>00381 <span class="comment">/**</span>
<a name="l00382"></a>00382 <span class="comment"> * Set the default profileto connect to after initial startup</span>
<a name="l00383"></a>00383 <span class="comment"> * @param profile The profile to connect to, 0 = none, 1 = custom profile, 2 = default</span>
<a name="l00384"></a>00384 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00385"></a>00385 <span class="comment"> */</span>
<a name="l00386"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga789ea83bf9e9616742dc7fae399bef71">00386</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga789ea83bf9e9616742dc7fae399bef71">N2WsetDefaultProfile</a>(ubyte profile)
<a name="l00387"></a>00387 {
<a name="l00388"></a>00388   ubyte len;
<a name="l00389"></a>00389   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$COS%d\n&quot;</span>, profile);
<a name="l00390"></a>00390   writeDebugStreamLine(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00391"></a>00391   memset(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>));
<a name="l00392"></a>00392   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00393"></a>00393   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00394"></a>00394   wait1Msec(10);
<a name="l00395"></a>00395         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00396"></a>00396         <span class="keywordflow">return</span> (<a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>) == 1);
<a name="l00397"></a>00397 }
<a name="l00398"></a>00398 
<a name="l00399"></a>00399 <span class="comment"></span>
<a name="l00400"></a>00400 <span class="comment">/**</span>
<a name="l00401"></a>00401 <span class="comment"> * Check if a the custom profile exists.</span>
<a name="l00402"></a>00402 <span class="comment"> * @return true if the profile exists, false if it does not or an error occured.</span>
<a name="l00403"></a>00403 <span class="comment"> */</span>
<a name="l00404"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga518cfe843bc8f4d042405227a0a2f4ff">00404</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga518cfe843bc8f4d042405227a0a2f4ff">N2WCustomExist</a>()
<a name="l00405"></a>00405 {
<a name="l00406"></a>00406 
<a name="l00407"></a>00407   ubyte len;
<a name="l00408"></a>00408   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFKE\n&quot;</span>);
<a name="l00409"></a>00409   wait1Msec(100);
<a name="l00410"></a>00410         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00411"></a>00411         <span class="keywordflow">return</span> (<a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>) == 1);
<a name="l00412"></a>00412 }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414 <span class="comment"></span>
<a name="l00415"></a>00415 <span class="comment">/**</span>
<a name="l00416"></a>00416 <span class="comment"> * Enter or exit hibernation mode</span>
<a name="l00417"></a>00417 <span class="comment"> * @param hibernate enter hibernation mode if true, exit if false</span>
<a name="l00418"></a>00418 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00419"></a>00419 <span class="comment"> */</span>
<a name="l00420"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaf153be5c0c0c0d1d3ab0e545690aab26">00420</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gaf153be5c0c0c0d1d3ab0e545690aab26">N2WsetHibernate</a>(<span class="keywordtype">bool</span> hibernate)
<a name="l00421"></a>00421 {
<a name="l00422"></a>00422   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = (hibernate) ? <span class="stringliteral">&quot;$WFH\n&quot;</span> : <span class="stringliteral">&quot;WFO\n&quot;</span>;
<a name="l00423"></a>00423   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>))
<a name="l00424"></a>00424     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00425"></a>00425   wait1Msec(10);
<a name="l00426"></a>00426   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00427"></a>00427   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00428"></a>00428 }
<a name="l00429"></a>00429 
<a name="l00430"></a>00430 
<a name="l00431"></a>00431 <span class="comment"></span>
<a name="l00432"></a>00432 <span class="comment">/**</span>
<a name="l00433"></a>00433 <span class="comment"> * Enable or disable power saving</span>
<a name="l00434"></a>00434 <span class="comment"> * @param powersave enable powersaving if true, disable if false</span>
<a name="l00435"></a>00435 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00436"></a>00436 <span class="comment"> */</span>
<a name="l00437"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gac19e89faffd3abfbeb0c16a40c782df8">00437</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gac19e89faffd3abfbeb0c16a40c782df8">N2WsetPowerSave</a>(<span class="keywordtype">bool</span> powersave)
<a name="l00438"></a>00438 {
<a name="l00439"></a>00439   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = (powersave) ? <span class="stringliteral">&quot;$WFP1\n&quot;</span> : <span class="stringliteral">&quot;WFP0\n&quot;</span>;
<a name="l00440"></a>00440   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>))
<a name="l00441"></a>00441     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00442"></a>00442   wait1Msec(10);
<a name="l00443"></a>00443   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00444"></a>00444   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00445"></a>00445 }
<a name="l00446"></a>00446 
<a name="l00447"></a>00447 <span class="comment"></span>
<a name="l00448"></a>00448 <span class="comment">/**</span>
<a name="l00449"></a>00449 <span class="comment"> * Get the current connection status.</span>
<a name="l00450"></a>00450 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00451"></a>00451 <span class="comment"> */</span>
<a name="l00452"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga4d614d8aa6344f68393579251e0f57de">00452</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga4d614d8aa6344f68393579251e0f57de">N2WStatus</a>() {
<a name="l00453"></a>00453   ubyte len;
<a name="l00454"></a>00454   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;$WFGS\n&quot;</span>);
<a name="l00455"></a>00455   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00456"></a>00456         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00457"></a>00457         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00458"></a>00458 }
<a name="l00459"></a>00459 
<a name="l00460"></a>00460 <span class="comment"></span>
<a name="l00461"></a>00461 <span class="comment">/**</span>
<a name="l00462"></a>00462 <span class="comment"> * Are we connected to the WiFi network?</span>
<a name="l00463"></a>00463 <span class="comment"> * @return true if connected, false if not connected an error occured</span>
<a name="l00464"></a>00464 <span class="comment"> */</span>
<a name="l00465"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga2012c5479768124f2083dc643d7b4573">00465</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga2012c5479768124f2083dc643d7b4573">N2WConnected</a>() {
<a name="l00466"></a>00466         <span class="keywordflow">return</span> (<a class="code" href="group___n_x_t2_w_i_f_i.html#ga4d614d8aa6344f68393579251e0f57de">N2WStatus</a>() == 2);
<a name="l00467"></a>00467 }
<a name="l00468"></a>00468 
<a name="l00469"></a>00469 <span class="comment"></span>
<a name="l00470"></a>00470 <span class="comment">/**</span>
<a name="l00471"></a>00471 <span class="comment"> * Get the current IP address.  If the address could not be determined</span>
<a name="l00472"></a>00472 <span class="comment"> * 0.0.0.0 is returned.</span>
<a name="l00473"></a>00473 <span class="comment"> * @param IP the string to put the address into</span>
<a name="l00474"></a>00474 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00475"></a>00475 <span class="comment"> */</span>
<a name="l00476"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga75f932c01ab7aaf3ba965179b2773215">00476</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga75f932c01ab7aaf3ba965179b2773215">N2WgetIP</a>(<span class="keywordtype">string</span> &amp;IP) {
<a name="l00477"></a>00477   ubyte len;
<a name="l00478"></a>00478   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;$WFIP\n&quot;</span>;
<a name="l00479"></a>00479   memset(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>));
<a name="l00480"></a>00480   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00481"></a>00481   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00482"></a>00482         wait1Msec(100);
<a name="l00483"></a>00483         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00484"></a>00484 
<a name="l00485"></a>00485         <span class="keywordflow">if</span> (len &lt; 1)
<a name="l00486"></a>00486         {
<a name="l00487"></a>00487           IP = <span class="stringliteral">&quot;0.0.0.0&quot;</span>;
<a name="l00488"></a>00488           <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00489"></a>00489         }
<a name="l00490"></a>00490         <span class="keywordflow">else</span>
<a name="l00491"></a>00491         {
<a name="l00492"></a>00492           <a class="code" href="group___n_x_t2_w_i_f_i.html#ga02cfed21ceafe387f51c2614ba4acc6b">N2WgetStringResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, IP);
<a name="l00493"></a>00493           <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00494"></a>00494         }
<a name="l00495"></a>00495 }
<a name="l00496"></a>00496 
<a name="l00497"></a>00497 <span class="comment"></span>
<a name="l00498"></a>00498 <span class="comment">/**</span>
<a name="l00499"></a>00499 <span class="comment"> * Get the NXT2WIFI&#39;s MAC address.</span>
<a name="l00500"></a>00500 <span class="comment"> * @param mac string to hold MAC address</span>
<a name="l00501"></a>00501 <span class="comment"> */</span>
<a name="l00502"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gac0449df51c7daa839b3769d78f4ce517">00502</a> <span class="keywordtype">void</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gac0449df51c7daa839b3769d78f4ce517">N2WgetMAC</a>(<span class="keywordtype">string</span> &amp;mac)
<a name="l00503"></a>00503 {
<a name="l00504"></a>00504   ubyte len;
<a name="l00505"></a>00505   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$MAC\n&quot;</span>);
<a name="l00506"></a>00506   memset(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>));
<a name="l00507"></a>00507   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00508"></a>00508   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00509"></a>00509         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00510"></a>00510         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00511"></a>00511 
<a name="l00512"></a>00512         <span class="keywordflow">if</span> (len &lt; 1)
<a name="l00513"></a>00513         {
<a name="l00514"></a>00514           mac = <span class="stringliteral">&quot;00-00-00-00-00-00&quot;</span>;
<a name="l00515"></a>00515         }
<a name="l00516"></a>00516         <span class="keywordflow">else</span>
<a name="l00517"></a>00517   {
<a name="l00518"></a>00518     <a class="code" href="group___n_x_t2_w_i_f_i.html#ga02cfed21ceafe387f51c2614ba4acc6b">N2WgetStringResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, mac);
<a name="l00519"></a>00519   }
<a name="l00520"></a>00520 }
<a name="l00521"></a>00521 
<a name="l00522"></a>00522 <span class="comment"></span>
<a name="l00523"></a>00523 <span class="comment">/**</span>
<a name="l00524"></a>00524 <span class="comment"> * Open a UDP datastream to a remote host on a port</span>
<a name="l00525"></a>00525 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00526"></a>00526 <span class="comment"> * @param ip the IP address of the remote host</span>
<a name="l00527"></a>00527 <span class="comment"> * @param port the port of the service on the remote host</span>
<a name="l00528"></a>00528 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00529"></a>00529 <span class="comment"> */</span>
<a name="l00530"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga8e26fb26cd6daa62f7aeb52ad733ad1f">00530</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8e26fb26cd6daa62f7aeb52ad733ad1f">N2WUDPOpenClient</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">string</span> ip, <span class="keywordtype">int</span> port) {
<a name="l00531"></a>00531   <span class="keywordtype">int</span> index = 0;
<a name="l00532"></a>00532   <span class="keywordtype">int</span> respOK = 0;
<a name="l00533"></a>00533   ubyte len;
<a name="l00534"></a>00534   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPOC%d?&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00535"></a>00535   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00536"></a>00536   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, ip);
<a name="l00537"></a>00537   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;,%d\n&quot;</span>, port);
<a name="l00538"></a>00538   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00539"></a>00539   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00540"></a>00540         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00541"></a>00541         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00542"></a>00542         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00543"></a>00543         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00544"></a>00544 }
<a name="l00545"></a>00545 
<a name="l00546"></a>00546 <span class="comment"></span>
<a name="l00547"></a>00547 <span class="comment">/**</span>
<a name="l00548"></a>00548 <span class="comment"> * Open a listening UDP socket on the specified port</span>
<a name="l00549"></a>00549 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00550"></a>00550 <span class="comment"> * @param port the port on which to start listening</span>
<a name="l00551"></a>00551 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00552"></a>00552 <span class="comment"> */</span>
<a name="l00553"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gabf82b9ae3ba7b692ca6d9ec75eabc80e">00553</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabf82b9ae3ba7b692ca6d9ec75eabc80e">N2WUDPOpenServer</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">int</span> port) {
<a name="l00554"></a>00554   <span class="keywordtype">int</span> index = 0;
<a name="l00555"></a>00555   <span class="keywordtype">int</span> respOK = 0;
<a name="l00556"></a>00556   ubyte len;
<a name="l00557"></a>00557   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPOS%d?%d\n&quot;</span>, <span class="keywordtype">id</span>, port);
<a name="l00558"></a>00558   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00559"></a>00559   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00560"></a>00560         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00561"></a>00561         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00562"></a>00562         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00563"></a>00563         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00564"></a>00564 }
<a name="l00565"></a>00565 
<a name="l00566"></a>00566 <span class="comment"></span>
<a name="l00567"></a>00567 <span class="comment">/**</span>
<a name="l00568"></a>00568 <span class="comment"> * Check if there are bytes available for reading on the specified connection.</span>
<a name="l00569"></a>00569 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00570"></a>00570 <span class="comment"> * @return the number of bytes available for reading</span>
<a name="l00571"></a>00571 <span class="comment"> */</span>
<a name="l00572"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gabfed470eee5a127b1453966627552ca9">00572</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabfed470eee5a127b1453966627552ca9">N2WUDPAvail</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00573"></a>00573   <span class="keywordtype">int</span> index = 0;
<a name="l00574"></a>00574   ubyte len;
<a name="l00575"></a>00575   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPL%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00576"></a>00576   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00577"></a>00577   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00578"></a>00578         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00579"></a>00579         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00580"></a>00580   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00581"></a>00581     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00582"></a>00582   wait1Msec(10);
<a name="l00583"></a>00583   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00584"></a>00584   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00585"></a>00585 }
<a name="l00586"></a>00586 
<a name="l00587"></a>00587 <span class="comment"></span>
<a name="l00588"></a>00588 <span class="comment">/**</span>
<a name="l00589"></a>00589 <span class="comment"> * Read the specified number of bytes from the connection ID.</span>
<a name="l00590"></a>00590 <span class="comment"> * Bytes are read into the RS485rxbuffer variable.</span>
<a name="l00591"></a>00591 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00592"></a>00592 <span class="comment"> * @param datalen the number of bytes to read</span>
<a name="l00593"></a>00593 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00594"></a>00594 <span class="comment"> */</span>
<a name="l00595"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga7a7ac805f528e56cc1de33f676670434">00595</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga7a7ac805f528e56cc1de33f676670434">N2WUDPRead</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">int</span> datalen) {
<a name="l00596"></a>00596   <span class="keywordtype">int</span> index = 0;
<a name="l00597"></a>00597   memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00598"></a>00598   ubyte offset;
<a name="l00599"></a>00599 
<a name="l00600"></a>00600   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPR%d?%d\n&quot;</span>, <span class="keywordtype">id</span>, datalen);
<a name="l00601"></a>00601   offset = (datalen &gt; 9) ? 8 : 7;
<a name="l00602"></a>00602   datalen += offset;
<a name="l00603"></a>00603   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00604"></a>00604   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00605"></a>00605         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00606"></a>00606         <span class="comment">//wait1Msec(100);</span>
<a name="l00607"></a>00607         <a class="code" href="group__common-rs485.html#gaa4304b64044355323adc1c6c7356ee44">RS485readLargeResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, datalen, 100);
<a name="l00608"></a>00608 
<a name="l00609"></a>00609 
<a name="l00610"></a>00610         <span class="comment">// This part seperates the data from the pre-amble</span>
<a name="l00611"></a>00611         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>); i++)
<a name="l00612"></a>00612         {
<a name="l00613"></a>00613           <span class="keywordflow">if</span> (<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i] != <span class="charliteral">&#39;,&#39;</span>)
<a name="l00614"></a>00614           {
<a name="l00615"></a>00615             <span class="keywordflow">continue</span>;
<a name="l00616"></a>00616           }
<a name="l00617"></a>00617           <span class="keywordflow">else</span>
<a name="l00618"></a>00618           {
<a name="l00619"></a>00619             <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00620"></a>00620             memmove(&amp;<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[0], &amp;<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[offset+1], datalen);
<a name="l00621"></a>00621             <span class="keywordflow">return</span> atoi(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00622"></a>00622           }
<a name="l00623"></a>00623         }
<a name="l00624"></a>00624         <span class="keywordflow">return</span> 0;
<a name="l00625"></a>00625 }
<a name="l00626"></a>00626 
<a name="l00627"></a>00627 <span class="comment"></span>
<a name="l00628"></a>00628 <span class="comment">/**</span>
<a name="l00629"></a>00629 <span class="comment"> * Write the specified number of bytes to the connection ID.</span>
<a name="l00630"></a>00630 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00631"></a>00631 <span class="comment"> * @param data the tHugeByteArray containing the data to be transmitted</span>
<a name="l00632"></a>00632 <span class="comment"> * @param datalen the number of bytes to read</span>
<a name="l00633"></a>00633 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00634"></a>00634 <span class="comment"> */</span>
<a name="l00635"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga7f7ff271d365cd3e9d37da277293869e">00635</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga7f7ff271d365cd3e9d37da277293869e">N2WUDPWrite</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <a class="code" href="group__common.html#gacc2928041c5ff8e7f2ddef1e88431e80">tHugeByteArray</a> &amp;data, <span class="keywordtype">int</span> datalen) {
<a name="l00636"></a>00636   <span class="comment">// writeDebugStreamLine(&quot;N2WUDPWrite&quot;);</span>
<a name="l00637"></a>00637   <span class="keywordtype">int</span> index = 0;
<a name="l00638"></a>00638   <span class="keywordtype">int</span> respOK;
<a name="l00639"></a>00639   memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00640"></a>00640 
<a name="l00641"></a>00641   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPW%d?%d,&quot;</span>, <span class="keywordtype">id</span>, datalen);
<a name="l00642"></a>00642   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00643"></a>00643   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>((<a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a>)<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, &amp;data[0], datalen);
<a name="l00644"></a>00644   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00645"></a>00645   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(RS485txbuffer, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00646"></a>00646   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(RS485txbuffer, index);
<a name="l00647"></a>00647   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00648"></a>00648         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00649"></a>00649         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00650"></a>00650 }
<a name="l00651"></a>00651 
<a name="l00652"></a>00652 <span class="comment"></span>
<a name="l00653"></a>00653 <span class="comment">/**</span>
<a name="l00654"></a>00654 <span class="comment"> * Close the specified connection.  Use 0 to close all connections</span>
<a name="l00655"></a>00655 <span class="comment"> * @param id the connection ID to use, can be 1 to 4 or 0 for all</span>
<a name="l00656"></a>00656 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00657"></a>00657 <span class="comment"> */</span>
<a name="l00658"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga853a53631c8e4f961e6dd9a2b025ddb9">00658</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga853a53631c8e4f961e6dd9a2b025ddb9">N2WUDPClose</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00659"></a>00659         StringFormat(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPX%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00660"></a>00660   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00661"></a>00661   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00662"></a>00662     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00663"></a>00663   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00664"></a>00664   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00665"></a>00665 }
<a name="l00666"></a>00666 
<a name="l00667"></a>00667 <span class="comment"></span>
<a name="l00668"></a>00668 <span class="comment">/**</span>
<a name="l00669"></a>00669 <span class="comment"> * Flush the buffers of the specified connection</span>
<a name="l00670"></a>00670 <span class="comment"> * @param id the connection ID to use, can be 1 to 4 or 0 for all</span>
<a name="l00671"></a>00671 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00672"></a>00672 <span class="comment"> */</span>
<a name="l00673"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga10eff429e5d4857cc066ddae0994e759">00673</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga10eff429e5d4857cc066ddae0994e759">N2WUDPFlush</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00674"></a>00674         StringFormat(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$UDPF%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00675"></a>00675   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00676"></a>00676   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00677"></a>00677     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00678"></a>00678   wait1Msec(10);
<a name="l00679"></a>00679   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00680"></a>00680   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00681"></a>00681 }
<a name="l00682"></a>00682 
<a name="l00683"></a>00683 <span class="comment"></span>
<a name="l00684"></a>00684 <span class="comment">/**</span>
<a name="l00685"></a>00685 <span class="comment"> * Open a TCP connection to a remote host on a port</span>
<a name="l00686"></a>00686 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00687"></a>00687 <span class="comment"> * @param host the IP address of name of the remote host</span>
<a name="l00688"></a>00688 <span class="comment"> * @param port the port of the service on the remote host</span>
<a name="l00689"></a>00689 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00690"></a>00690 <span class="comment"> */</span>
<a name="l00691"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga6a0b83afc5568dafe0cc76020e769a87">00691</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga6a0b83afc5568dafe0cc76020e769a87">N2WTCPOpenClient</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">string</span> host, <span class="keywordtype">int</span> port) {
<a name="l00692"></a>00692   <span class="keywordtype">int</span> index = 0;
<a name="l00693"></a>00693   <span class="keywordtype">int</span> respOK = 0;
<a name="l00694"></a>00694   ubyte len;
<a name="l00695"></a>00695   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPOC%d?&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00696"></a>00696   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00697"></a>00697   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, host);
<a name="l00698"></a>00698   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;,%d\n&quot;</span>, port);
<a name="l00699"></a>00699   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00700"></a>00700   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00701"></a>00701         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00702"></a>00702         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00703"></a>00703         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00704"></a>00704         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00705"></a>00705 }
<a name="l00706"></a>00706 
<a name="l00707"></a>00707 <span class="comment"></span>
<a name="l00708"></a>00708 <span class="comment">/**</span>
<a name="l00709"></a>00709 <span class="comment"> * Open a TCP connection to a remote host on a port</span>
<a name="l00710"></a>00710 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00711"></a>00711 <span class="comment"> * @param host the IP address of name of the remote host</span>
<a name="l00712"></a>00712 <span class="comment"> * @param port the port of the service on the remote host</span>
<a name="l00713"></a>00713 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00714"></a>00714 <span class="comment"> */</span>
<a name="l00715"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga7ff13f73e614148c4acd1f6595afe5fa">00715</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga6a0b83afc5568dafe0cc76020e769a87">N2WTCPOpenClient</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">char</span> *host, <span class="keywordtype">int</span> port) {
<a name="l00716"></a>00716   writeDebugStreamLine(<span class="stringliteral">&quot;TCPOC pointer version&quot;</span>);
<a name="l00717"></a>00717   <span class="keywordtype">int</span> index = 0;
<a name="l00718"></a>00718   <span class="keywordtype">int</span> respOK = 0;
<a name="l00719"></a>00719   ubyte len;
<a name="l00720"></a>00720   writeDebugStreamLine(<span class="stringliteral">&quot;host: %s&quot;</span>, host);
<a name="l00721"></a>00721   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPOC%d?&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00722"></a>00722   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00723"></a>00723   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, host);
<a name="l00724"></a>00724   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;,%d\n&quot;</span>, port);
<a name="l00725"></a>00725   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00726"></a>00726   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00727"></a>00727         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00728"></a>00728         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00729"></a>00729         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00730"></a>00730         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00731"></a>00731 }
<a name="l00732"></a>00732 
<a name="l00733"></a>00733 <span class="comment"></span>
<a name="l00734"></a>00734 <span class="comment">/**</span>
<a name="l00735"></a>00735 <span class="comment"> * Open a listening UDP socket on the specified port</span>
<a name="l00736"></a>00736 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00737"></a>00737 <span class="comment"> * @param port the port on which to start listening</span>
<a name="l00738"></a>00738 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00739"></a>00739 <span class="comment"> */</span>
<a name="l00740"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga94933ef9ec1dd6d41593aeb7cc01db71">00740</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga94933ef9ec1dd6d41593aeb7cc01db71">N2WTCPOpenServer</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">int</span> port) {
<a name="l00741"></a>00741   <span class="keywordtype">int</span> index = 0;
<a name="l00742"></a>00742   <span class="keywordtype">int</span> respOK = 0;
<a name="l00743"></a>00743   ubyte len;
<a name="l00744"></a>00744   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPOS%d?%d\n&quot;</span>, <span class="keywordtype">id</span>, port);
<a name="l00745"></a>00745   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00746"></a>00746   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00747"></a>00747         wait1Msec(500);
<a name="l00748"></a>00748         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00749"></a>00749         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00750"></a>00750         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00751"></a>00751 }
<a name="l00752"></a>00752 
<a name="l00753"></a>00753 <span class="comment"></span>
<a name="l00754"></a>00754 <span class="comment">/**</span>
<a name="l00755"></a>00755 <span class="comment"> * Closes a connection to a remote client</span>
<a name="l00756"></a>00756 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00757"></a>00757 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00758"></a>00758 <span class="comment"> */</span>
<a name="l00759"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gabb2b4a155b438f699ce3f58cc4690a20">00759</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabb2b4a155b438f699ce3f58cc4690a20">N2WTCPDetachClient</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00760"></a>00760   <span class="keywordtype">int</span> index = 0;
<a name="l00761"></a>00761   <span class="keywordtype">int</span> respOK = 0;
<a name="l00762"></a>00762   ubyte len;
<a name="l00763"></a>00763   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPD%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00764"></a>00764   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00765"></a>00765   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00766"></a>00766         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00767"></a>00767         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00768"></a>00768         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00769"></a>00769         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00770"></a>00770 }
<a name="l00771"></a>00771 
<a name="l00772"></a>00772 <span class="comment"></span>
<a name="l00773"></a>00773 <span class="comment">/**</span>
<a name="l00774"></a>00774 <span class="comment"> * Close the specified connection</span>
<a name="l00775"></a>00775 <span class="comment"> * @param id the connection ID to use, can be 1 to 4 or 0 for all</span>
<a name="l00776"></a>00776 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00777"></a>00777 <span class="comment"> */</span>
<a name="l00778"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga83d5a491bba4318f2b41b6eeebbc95df">00778</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga83d5a491bba4318f2b41b6eeebbc95df">N2WTCPClose</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00779"></a>00779         StringFormat(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPX%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00780"></a>00780   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00781"></a>00781   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00782"></a>00782     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00783"></a>00783   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00784"></a>00784   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00785"></a>00785 }
<a name="l00786"></a>00786 
<a name="l00787"></a>00787 <span class="comment"></span>
<a name="l00788"></a>00788 <span class="comment">/**</span>
<a name="l00789"></a>00789 <span class="comment"> * Flush the buffers of the specified connection</span>
<a name="l00790"></a>00790 <span class="comment"> * @param id the connection ID to use, can be 1 to 4 or 0 for all</span>
<a name="l00791"></a>00791 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00792"></a>00792 <span class="comment"> */</span>
<a name="l00793"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga35c97dd880f8726d3e1d5135ba6875c8">00793</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga35c97dd880f8726d3e1d5135ba6875c8">N2WTCPFlush</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00794"></a>00794         StringFormat(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPF%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00795"></a>00795   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00796"></a>00796   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00797"></a>00797     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00798"></a>00798   wait1Msec(10);
<a name="l00799"></a>00799   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00800"></a>00800   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00801"></a>00801 }
<a name="l00802"></a>00802 
<a name="l00803"></a>00803 <span class="comment"></span>
<a name="l00804"></a>00804 <span class="comment">/**</span>
<a name="l00805"></a>00805 <span class="comment"> * Check if there are bytes available for reading on the specified connection.</span>
<a name="l00806"></a>00806 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00807"></a>00807 <span class="comment"> * @return the number of bytes available for reading</span>
<a name="l00808"></a>00808 <span class="comment"> */</span>
<a name="l00809"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gad03127c6ae3da843d91f77e3bb27bb31">00809</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gad03127c6ae3da843d91f77e3bb27bb31">N2WTCPAvail</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {
<a name="l00810"></a>00810   <span class="keywordtype">int</span> index = 0;
<a name="l00811"></a>00811   ubyte len;
<a name="l00812"></a>00812   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPL%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00813"></a>00813   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00814"></a>00814   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00815"></a>00815         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00816"></a>00816         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00817"></a>00817         <span class="keywordflow">return</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00818"></a>00818 }
<a name="l00819"></a>00819 
<a name="l00820"></a>00820 <span class="comment"></span>
<a name="l00821"></a>00821 <span class="comment">/**</span>
<a name="l00822"></a>00822 <span class="comment"> * Read the specified number of bytes from the connection ID.</span>
<a name="l00823"></a>00823 <span class="comment"> * Bytes are read into the RS485rxbuffer variable.</span>
<a name="l00824"></a>00824 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00825"></a>00825 <span class="comment"> * @param datalen the number of bytes to read</span>
<a name="l00826"></a>00826 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00827"></a>00827 <span class="comment"> */</span>
<a name="l00828"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gadb790227d5aae36490f830db97b5e85e">00828</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gadb790227d5aae36490f830db97b5e85e">N2WTCPRead</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">int</span> datalen) {
<a name="l00829"></a>00829   <span class="keywordtype">int</span> index = 0;
<a name="l00830"></a>00830   memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00831"></a>00831   ubyte offset;
<a name="l00832"></a>00832 
<a name="l00833"></a>00833   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPR%d?%d\n&quot;</span>, <span class="keywordtype">id</span>, datalen);
<a name="l00834"></a>00834   offset = (datalen &gt; 9) ? 8 : 7;
<a name="l00835"></a>00835   datalen += offset;
<a name="l00836"></a>00836   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00837"></a>00837   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00838"></a>00838         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00839"></a>00839         <a class="code" href="group__common-rs485.html#gaa4304b64044355323adc1c6c7356ee44">RS485readLargeResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, datalen, 100);
<a name="l00840"></a>00840 
<a name="l00841"></a>00841 
<a name="l00842"></a>00842         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>); i++)
<a name="l00843"></a>00843         {
<a name="l00844"></a>00844           <span class="keywordflow">if</span> (<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i] != <span class="charliteral">&#39;,&#39;</span>)
<a name="l00845"></a>00845           {
<a name="l00846"></a>00846             <span class="keywordflow">continue</span>;
<a name="l00847"></a>00847           }
<a name="l00848"></a>00848           <span class="keywordflow">else</span>
<a name="l00849"></a>00849           {
<a name="l00850"></a>00850             <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00851"></a>00851             memmove(&amp;<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[0], &amp;<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[offset+1], datalen);
<a name="l00852"></a>00852             <span class="keywordflow">return</span> atoi(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00853"></a>00853           }
<a name="l00854"></a>00854         }
<a name="l00855"></a>00855         <span class="keywordflow">return</span> 0;
<a name="l00856"></a>00856 }
<a name="l00857"></a>00857 
<a name="l00858"></a>00858 <span class="comment"></span>
<a name="l00859"></a>00859 <span class="comment">/**</span>
<a name="l00860"></a>00860 <span class="comment"> * Write the specified number of bytes to the connection ID.</span>
<a name="l00861"></a>00861 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00862"></a>00862 <span class="comment"> * @param data the tHugeByteArray containing the data to be transmitted</span>
<a name="l00863"></a>00863 <span class="comment"> * @param datalen the number of bytes to read</span>
<a name="l00864"></a>00864 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00865"></a>00865 <span class="comment"> */</span>
<a name="l00866"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gabaa4672cbcc39d98359ae5926e6fa852">00866</a> <span class="keywordtype">int</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaa4672cbcc39d98359ae5926e6fa852">N2WTCPWrite</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <a class="code" href="group__common.html#gacc2928041c5ff8e7f2ddef1e88431e80">tHugeByteArray</a> &amp;data, <span class="keywordtype">int</span> datalen)
<a name="l00867"></a>00867 {
<a name="l00868"></a>00868   writeDebugStream(<span class="stringliteral">&quot;N2WTCPWrite: &quot;</span>);
<a name="l00869"></a>00869   writeDebugStreamLine(<span class="stringliteral">&quot;datalen: %d&quot;</span>, datalen);
<a name="l00870"></a>00870   <span class="keywordtype">int</span> index = 0;
<a name="l00871"></a>00871   <span class="keywordtype">int</span> respOK;
<a name="l00872"></a>00872   memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l00873"></a>00873 
<a name="l00874"></a>00874   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPW%d?%d,&quot;</span>, <span class="keywordtype">id</span>, datalen);
<a name="l00875"></a>00875   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00876"></a>00876   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, &amp;data[0], datalen);
<a name="l00877"></a>00877   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00878"></a>00878   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l00879"></a>00879   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l00880"></a>00880   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00881"></a>00881         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l00882"></a>00882         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00883"></a>00883 }
<a name="l00884"></a>00884 
<a name="l00885"></a>00885 <span class="comment"></span>
<a name="l00886"></a>00886 <span class="comment">/**</span>
<a name="l00887"></a>00887 <span class="comment"> * Get the remote client&#39;s IP address</span>
<a name="l00888"></a>00888 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00889"></a>00889 <span class="comment"> * @param ip string to hold IP address</span>
<a name="l00890"></a>00890 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00891"></a>00891 <span class="comment"> */</span>
<a name="l00892"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#gaaf7765cdc6fc8a1617080e59634bb385">00892</a> <span class="keywordtype">void</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#gaaf7765cdc6fc8a1617080e59634bb385">N2WTCPClientIP</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">string</span> &amp;ip)
<a name="l00893"></a>00893 {
<a name="l00894"></a>00894   ubyte len;
<a name="l00895"></a>00895   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPSI%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00896"></a>00896   memset(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>));
<a name="l00897"></a>00897   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00898"></a>00898   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00899"></a>00899         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00900"></a>00900         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00901"></a>00901 
<a name="l00902"></a>00902         <span class="keywordflow">if</span> (len &lt; 1)
<a name="l00903"></a>00903         {
<a name="l00904"></a>00904           ip = <span class="stringliteral">&quot;0.0.0.0&quot;</span>;
<a name="l00905"></a>00905         }
<a name="l00906"></a>00906         <span class="keywordflow">else</span>
<a name="l00907"></a>00907   {
<a name="l00908"></a>00908     <a class="code" href="group___n_x_t2_w_i_f_i.html#ga02cfed21ceafe387f51c2614ba4acc6b">N2WgetStringResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, ip);
<a name="l00909"></a>00909   }
<a name="l00910"></a>00910 }
<a name="l00911"></a>00911 
<a name="l00912"></a>00912 <span class="comment"></span>
<a name="l00913"></a>00913 <span class="comment">/**</span>
<a name="l00914"></a>00914 <span class="comment"> * Get the remote client&#39;s MAC address.  Only useful for local network client.</span>
<a name="l00915"></a>00915 <span class="comment"> * @param id the connection ID to use, can be 1 to 4</span>
<a name="l00916"></a>00916 <span class="comment"> * @param mac string to hold MAC address</span>
<a name="l00917"></a>00917 <span class="comment"> */</span>
<a name="l00918"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga6d8484108baeaa94ac6df7df79e190ca">00918</a> <span class="keywordtype">void</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga6d8484108baeaa94ac6df7df79e190ca">N2WTCPClientMAC</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">string</span> &amp;mac)
<a name="l00919"></a>00919 {
<a name="l00920"></a>00920   ubyte len;
<a name="l00921"></a>00921   sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, <span class="stringliteral">&quot;$TCPSM%d\n&quot;</span>, <span class="keywordtype">id</span>);
<a name="l00922"></a>00922   memset(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>));
<a name="l00923"></a>00923   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00924"></a>00924   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00925"></a>00925         <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l00926"></a>00926         <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00927"></a>00927 
<a name="l00928"></a>00928         <span class="keywordflow">if</span> (len &lt; 1)
<a name="l00929"></a>00929         {
<a name="l00930"></a>00930           mac = <span class="stringliteral">&quot;00-00-00-00-00-00&quot;</span>;
<a name="l00931"></a>00931         }
<a name="l00932"></a>00932         <span class="keywordflow">else</span>
<a name="l00933"></a>00933   {
<a name="l00934"></a>00934     <a class="code" href="group___n_x_t2_w_i_f_i.html#ga02cfed21ceafe387f51c2614ba4acc6b">N2WgetStringResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, mac);
<a name="l00935"></a>00935   }
<a name="l00936"></a>00936 }
<a name="l00937"></a>00937 
<a name="l00938"></a>00938 <span class="comment"></span>
<a name="l00939"></a>00939 <span class="comment">/**</span>
<a name="l00940"></a>00940 <span class="comment"> * Enable the built-in webserver.  This cannot be used together with</span>
<a name="l00941"></a>00941 <span class="comment"> * normal TCP/UDP operations.</span>
<a name="l00942"></a>00942 <span class="comment"> * @param enable enables the web server if set to true, disables it if false</span>
<a name="l00943"></a>00943 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00944"></a>00944 <span class="comment"> */</span>
<a name="l00945"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga607315267df26ff4000ee425fe567539">00945</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga607315267df26ff4000ee425fe567539">N2WenableWS</a>(<span class="keywordtype">bool</span> enable) {
<a name="l00946"></a>00946   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = (enable) ? <span class="stringliteral">&quot;$SRV=1\n&quot;</span> : <span class="stringliteral">&quot;$SRV=0\n&quot;</span>;
<a name="l00947"></a>00947   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l00948"></a>00948   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l00949"></a>00949     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00950"></a>00950   wait1Msec(10);
<a name="l00951"></a>00951   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00952"></a>00952   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00953"></a>00953 }
<a name="l00954"></a>00954 <span class="comment"></span>
<a name="l00955"></a>00955 <span class="comment">/**</span>
<a name="l00956"></a>00956 <span class="comment"> * Read data from the web server.  This cannot be used together with</span>
<a name="l00957"></a>00957 <span class="comment"> * normal TCP/UDP operations. \n</span>
<a name="l00958"></a>00958 <span class="comment"> * Type can be one of the following:</span>
<a name="l00959"></a>00959 <span class="comment"> * - WS_WEBLABEL</span>
<a name="l00960"></a>00960 <span class="comment"> * - WS_WEBBUTTON</span>
<a name="l00961"></a>00961 <span class="comment"> * - WS_WEBCHECKBOX</span>
<a name="l00962"></a>00962 <span class="comment"> * - WS_WEBSLIDER</span>
<a name="l00963"></a>00963 <span class="comment"> * @param type the type of widget</span>
<a name="l00964"></a>00964 <span class="comment"> * @param ID ID of the element that was pressed or submitted</span>
<a name="l00965"></a>00965 <span class="comment"> * @param state additional data from the UI element</span>
<a name="l00966"></a>00966 <span class="comment"> * @param value the value of the UI element</span>
<a name="l00967"></a>00967 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00968"></a>00968 <span class="comment"> */</span>
<a name="l00969"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga51eb3a733a2308f77d380db47496397e">00969</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga51eb3a733a2308f77d380db47496397e">N2WreadWS</a>(ubyte &amp;type, ubyte &amp;ID, ubyte &amp;state, ubyte &amp;value)
<a name="l00970"></a>00970 {
<a name="l00971"></a>00971   ubyte avail = nxtGetAvailHSBytes();
<a name="l00972"></a>00972   <span class="keywordflow">if</span> (avail &gt;= 5)
<a name="l00973"></a>00973   {
<a name="l00974"></a>00974     nxtReadRawHS(&amp;<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[0], avail);
<a name="l00975"></a>00975     writeDebugStream(<span class="stringliteral">&quot;N2WreadWS[%d]: &quot;</span>, avail);
<a name="l00976"></a>00976 
<a name="l00977"></a>00977     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; avail - 2; i++)
<a name="l00978"></a>00978     {
<a name="l00979"></a>00979       <span class="keywordflow">if</span> ((<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i] == 0x00) &amp;&amp; (<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i+1] == 0x80) &amp;&amp; (<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i+2] == 0x14))
<a name="l00980"></a>00980       {
<a name="l00981"></a>00981         type = <a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i+3];
<a name="l00982"></a>00982         ID = <a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i+4];
<a name="l00983"></a>00983         state = <a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i+5];
<a name="l00984"></a>00984         value = <a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[i+6];
<a name="l00985"></a>00985         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00986"></a>00986       }
<a name="l00987"></a>00987     }
<a name="l00988"></a>00988   }
<a name="l00989"></a>00989   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00990"></a>00990 }
<a name="l00991"></a>00991 
<a name="l00992"></a>00992 <span class="comment"></span>
<a name="l00993"></a>00993 <span class="comment">/**</span>
<a name="l00994"></a>00994 <span class="comment"> * Write data to the webserver. \n</span>
<a name="l00995"></a>00995 <span class="comment"> * Type can be one of the following:</span>
<a name="l00996"></a>00996 <span class="comment"> * - WS_WEBLABEL</span>
<a name="l00997"></a>00997 <span class="comment"> * - WS_WEBBUTTON</span>
<a name="l00998"></a>00998 <span class="comment"> * - WS_WEBCHECKBOX</span>
<a name="l00999"></a>00999 <span class="comment"> * - WS_WEBSLIDER</span>
<a name="l01000"></a>01000 <span class="comment"> * - WS_WEBBARGRAPH</span>
<a name="l01001"></a>01001 <span class="comment"> * @param type the type of webpage element</span>
<a name="l01002"></a>01002 <span class="comment"> * @param id the field number in the web page</span>
<a name="l01003"></a>01003 <span class="comment"> * @param wsmessage data to be transmitted</span>
<a name="l01004"></a>01004 <span class="comment"> * @param wsmsglen length of the data</span>
<a name="l01005"></a>01005 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l01006"></a>01006 <span class="comment"> */</span>
<a name="l01007"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga007dff56d153169bea6f5419d05c61b9">01007</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga007dff56d153169bea6f5419d05c61b9">N2WwriteWS</a>(ubyte type, ubyte <span class="keywordtype">id</span>, <a class="code" href="group__common.html#gacc2928041c5ff8e7f2ddef1e88431e80">tHugeByteArray</a> &amp;wsmessage, ubyte wsmsglen)
<a name="l01008"></a>01008 {
<a name="l01009"></a>01009         writeDebugStream(<span class="stringliteral">&quot;N2WwriteWS: &quot;</span>);
<a name="l01010"></a>01010         writeDebugStreamLine(<span class="stringliteral">&quot;datalen: %d, id: %d&quot;</span>, wsmsglen, <span class="keywordtype">id</span>);
<a name="l01011"></a>01011         <span class="keywordflow">for</span> (ubyte i = 0; i &lt; wsmsglen; i++)
<a name="l01012"></a>01012         {
<a name="l01013"></a>01013           writeDebugStream(<span class="stringliteral">&quot;0x%2X &quot;</span>, wsmessage[i]);
<a name="l01014"></a>01014         }
<a name="l01015"></a>01015         writeDebugStreamLine(<span class="stringliteral">&quot; &quot;</span>);
<a name="l01016"></a>01016         <span class="keywordtype">int</span> index = 0;
<a name="l01017"></a>01017         <span class="keywordtype">int</span> respOK;
<a name="l01018"></a>01018         memset(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, 0, 20);
<a name="l01019"></a>01019 
<a name="l01020"></a>01020         <span class="keywordtype">string</span> web;
<a name="l01021"></a>01021         <span class="keywordflow">switch</span> (type)
<a name="l01022"></a>01022         {
<a name="l01023"></a>01023                 <span class="keywordflow">case</span> 1: web = <span class="stringliteral">&quot;$WEBLBL%d?%d,&quot;</span>; <span class="keywordflow">break</span>;
<a name="l01024"></a>01024                 <span class="keywordflow">case</span> 2: web = <span class="stringliteral">&quot;$WEBBTN%d?%d,&quot;</span>; <span class="keywordflow">break</span>;
<a name="l01025"></a>01025                 <span class="keywordflow">case</span> 3: web = <span class="stringliteral">&quot;$WEBCHK%d?%d,&quot;</span>; <span class="keywordflow">break</span>;
<a name="l01026"></a>01026                 <span class="keywordflow">case</span> 4: web = <span class="stringliteral">&quot;$WEBSLD%d?%d,&quot;</span>; <span class="keywordflow">break</span>;
<a name="l01027"></a>01027                 <span class="keywordflow">case</span> 5: web = <span class="stringliteral">&quot;$WEBBAR%d?%d,&quot;</span>; <span class="keywordflow">break</span>;
<a name="l01028"></a>01028                 <span class="keywordflow">default</span>: <span class="keywordflow">break</span>;
<a name="l01029"></a>01029         }
<a name="l01030"></a>01030 
<a name="l01031"></a>01031         sprintf(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, web, <span class="keywordtype">id</span>, wsmsglen);
<a name="l01032"></a>01032   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l01033"></a>01033   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, &amp;wsmessage[0], wsmsglen);
<a name="l01034"></a>01034   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l01035"></a>01035 
<a name="l01036"></a>01036   index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>);
<a name="l01037"></a>01037   <a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, index);
<a name="l01038"></a>01038   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga8cad34ee07c9a294819f0070c94e1720">N2WchillOut</a>();
<a name="l01039"></a>01039         respOK = <a class="code" href="group___n_x_t2_w_i_f_i.html#gabaad0084f545d07e190898c2398fc73a">N2WgetNumericResponse</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>);
<a name="l01040"></a>01040         <span class="keywordflow">return</span> (respOK == 1) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l01041"></a>01041 }
<a name="l01042"></a>01042 
<a name="l01043"></a>01043 
<a name="l01044"></a>01044 
<a name="l01045"></a>01045 
<a name="l01046"></a>01046 <span class="comment"></span>
<a name="l01047"></a>01047 <span class="comment">/**</span>
<a name="l01048"></a>01048 <span class="comment"> * Clears all webpage fields.  This cannot be used together with</span>
<a name="l01049"></a>01049 <span class="comment"> * normal TCP/UDP operations.</span>
<a name="l01050"></a>01050 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l01051"></a>01051 <span class="comment"> */</span>
<a name="l01052"></a><a class="code" href="group___n_x_t2_w_i_f_i.html#ga456b3ed57f83c56171dcd3f1e678f401">01052</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t2_w_i_f_i.html#ga456b3ed57f83c56171dcd3f1e678f401">N2WclearFields</a>() {
<a name="l01053"></a>01053   <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a> = <span class="stringliteral">&quot;$RXD\n&quot;</span>;
<a name="l01054"></a>01054   memcpy(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, <a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>));
<a name="l01055"></a>01055   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#ga7c456c09f2a2dd29ff53d20c8a77f42b">RS485write</a>(<a class="code" href="group__common-rs485.html#ga76b40f6d5142bd650f910cd6cd19c588">RS485txbuffer</a>, strlen(<a class="code" href="group___n_x_t2_w_i_f_i.html#ga64242f37fef710702a96a53849069503">N2WscratchString</a>)))
<a name="l01056"></a>01056     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l01057"></a>01057   wait1Msec(10);
<a name="l01058"></a>01058   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l01059"></a>01059   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l01060"></a>01060 }
<a name="l01061"></a>01061 
<a name="l01062"></a>01062 
<a name="l01063"></a>01063 <span class="preprocessor">#endif // __N2W_H__</span>
<a name="l01064"></a>01064 <span class="preprocessor"></span>
<a name="l01065"></a>01065 <span class="comment">/*</span>
<a name="l01066"></a>01066 <span class="comment"> * $Id: benedettelli-nxt2wifi.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l01067"></a>01067 <span class="comment"> */</span>
<a name="l01068"></a>01068 <span class="comment">/* @} */</span>
<a name="l01069"></a>01069 <span class="comment">/* @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
